<?php
class controller_module_navs extends __registry_controller {

    public $_ = array();

    public function __construct() {
        parent::add_object(array(
            'model_module_navs','system_view'
        ));
        $this->_layout = NULL;
    }

    public function index()
    {
		$this->_['url_base'] = URL_BASE;
		$shtml = '';

        $html = $this->view->view_display_module('navs');
        $this->arrBlockHtml = $this->view->view_get_block_html($html);
		
		$arr_com = $this->model_navs_get_com();

		if(!empty($arr_com))
		foreach($arr_com as $com)
		{
			$arr_row = array(
				'urlCat'=>URL_BASE.'admin/'.$com['SeoKey'].'/',
				'Categories'=>$com['CatName'],
                'catCom'=>$com['Com'],
                'catId'=>2,
			);

            $shtml .= $this->view->view_assign($this->arrBlockHtml['Cat'],$arr_row);
            $shtml .= $this->arrBlockHtml['Cli'];
		}

		$strhtml = $this->view->view_assign_block($html,array('htmlCat'=>$shtml));

		return $strhtml;
    }
	
	private function category($PID,$COM)
	{
		if(!isset($strHtml)) { $strHtml = Null; }
		$i=0;
		$arr = $this->model_navs_get_cat($PID,$COM); 
		if(!empty($arr))
		{
			foreach($arr as $row)
			{
				$r = $this->model_navs_get_com($row["Com"]);
				$arrVal = array('Categories'=>$row["CatName"],'urlCat'=>URL_BASE.'admin/'.$r["SeoKey"].'/'.$row["SeoKey"]);
				$strHtml .= $this->view->view_assign($this->arrBlockHtml['Cat'], $arrVal);
				
				
				if(!empty($row['ID']))
				$strChild = $this->category($row['ID'],NULL);
				if($strChild)
				{
					$strHtml .= $this->arrBlockHtml['Oul'].$strChild.$this->arrBlockHtml['Cul'];
				}
				else{
					$strHtml .= $this->arrBlockHtml['Cli'];
				}
			$i++;
			}
		}

		return $strHtml;
	}
	
	public function index_ajax()
    {
		/* http://localhost/cms/admin/ajax/mod/navs/1/2/3 */

        $strHtml ="";
		$flag = $_POST['flag'];
		$catID = $_POST['catID'];
		$catCom = $_POST['catCom'];
        if($flag)
        {
            $strHtml = $this->category( $catCom, $catID);
            if($strHtml)
                $strHtml = "<ul>".$strHtml."</ul>";
        }
		return $strHtml;
	}
	
}